package com.example.mapper;

import com.example.entity.Spu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.SpuVo;
import com.example.vo.SpuItemVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author 12057
* @description 针对表【spu(spu信息)】的数据库操作Mapper
* @createDate 2024-05-13 13:32:12
* @Entity com.example.entity.Spu
*/
@Mapper
public interface SpuMapper extends BaseMapper<Spu> {
    @Select("select * from spu where category_id = #{categoryId}")
    List<SpuItemVo> getSpuItemByCategoryId(@Param("categoryId") Integer categoryId);

    @Select("select * from spu where name Like concat('%',#{keyword},'%')")
    List<SpuItemVo> getSpuItemList(@Param("keyword") String keyword);

    List<SpuItemVo> getSpuByCategoryId(List<Long> idList);

    String getSpuNameBySpuIds(Long spuIds);

    @Select("select name from store where id = #{storeId}")
    String getSpuStoreNameById(@Param("storeId") Long storeId);

    @Select("select name from goods_category where id = #{categoryId}")
    String getSpuCategoryNameById(@Param("categoryId") Long categoryId);

    @Update("update spu SET publish_status = #{status} where id = #{spuId}")
    int updateStatus(@Param("status") Integer status,@Param("spuId") Long spuId);

    //审核

    @Select("select * from admin_spu_exam")
    List<Spu> getExamSpuList();

    @Update("update admin_spu_exam SET publish_status = #{status} where id = #{spuId}")
    int updatePublishStatus(@Param("status") Integer status,@Param("spuId") Long spuId);

    @Insert("insert into spu (SELECT * from admin_spu_exam where id = #{spuId}) ")
    int addExamSpuToSpu(@Param("spuId") Long spuId);

    @Insert("insert into sku (select * from admin_sku_exam where spu_id = #{spuId})")
    int addExamSkuToSku(@Param("spuId") Long spuId);

    @Insert("insert into spu_desc (select * from admin_spu_desc_exam where spu_id = #{spuId})")
    int addExamSpuDescToSpuDesc(@Param("spuId") Long spuId);

    @Insert("insert into spu_attr_value (select * from admin_spu_attr_value_exam where spu_id = #{spuId})")
    int addExamSpuAttrToSpuAttr(@Param("spuId") Long spuId);

    int addExamSkuAttrToSkuAttr(List<Long> skuId);

    int addExamSkuImagesToSkuImages(List<Long> skuId);

    @Select("select id from admin_sku_exam where spu_id = #{spuId}")
    List<Long> getExamSkuIdsBySpuId(@Param("spuId") Long spuId);

    //卖
    @Select("select * from spu where store_id = #{storeId}")
    List<Spu> getStoreSpuList(@Param("storeId") Long storeId);
}




